today we will cover some api and axios
Create Your own api
write your api url under your routes/api.php. I'm writting like this:
the getapi function was actually using eloquent method to get the data from database called student_data table and turn the data structure into the json model.
after you create your own api you can use you own third party software to make a request to your api and get the data, for example in this article I'll use AXIOS. axios will send a request using nodejs, so we will take the response in our script. after we get what we wanted in javascript we could append it to our html pages.
for those who don't know axios go check this link.
AXIOS
import axios using cdn method:
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
make the request
axios.get('/user?ID=12345')
.then(function (response) {
// handle success
console.log(response);
})
.catch(function (error) {
// handle error
console.log(error);
})
.then(function () {
// always executed
});
after you get the resposne you could append the response value into your HTML page using either javascript or jquery.